<?php

namespace app\controllers;

use app\models\RobotsMongo;

class RobotsMController extends BaseController
{
    public function indexAction()
    {
        $robots = RobotsMongo::find();
        echo 'There are ',count($robots) . '<br/>';
        foreach ($robots as $robot) {
            echo 'id:' . $robot->getId() . '<br/>';
        }
    }

    public function saveAction()
    {
        $robot = new RobotsMongo();
        $robot->type = $this->request->get('type');
        $robot->name = $this->request->get('name');
        $robot->year = $this->request->get('year');
        $robot->price = $this->request->get('price');
        if ($robot->save()=== false) {
            echo 'catch Exception:<br/>';
            foreach ($robot->getMessages() as $message) {
                echo $message . '<br/>';
            }
            exit;
        }
        exit('ok');
    }
}